Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Episode 2 #15

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Episode 2 #15

wants to merge 5 commits into from

Conversation

meltar
Copy link

@meltar meltar commented Mar 11, 2013

I finished panda, tiger, and eagle.

@@ -1,21 +1,46 @@
require_relative "lib/movie"
require_relative "lib/api"

def get_average(movies, attribute)
if attribute == "score"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A cool thing in ruby --- you can tell movies what attribute you want it to collect. (collect is an alias for map, so I'm going to use map below)

data = movies.map(&:attribute)
data.inject(0.0) { |sum, rating| sum + rating } / data.size

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought there would likely be a cool Ruby thing that would do this in a generic way, but I'm unfamiliar with the &:attribute notation, so I couldn't get it to work. I need to spend some time going through the Enumerable module.

@jwo
Copy link
Member

jwo commented Mar 12, 2013

Looks really good! My only suggestion is that when you are rescue'ing the find_movie method, you could be rescuing too many exceptions. I'd rather the API that does the search know that there is a condition where a movie can be not-found, and return that condition.

The downside to a blank "rescue" is that it hides all exceptions that might occur, such as the website being down, or problems with your code.

@meltar
Copy link
Author

meltar commented Mar 12, 2013

That makes sense. I had to comment out the rescue sometimes in order to figure out why the program wasn't working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants